
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import ElementUI from "element-ui";
import drag from "@/directives/drag";
import "element-ui/lib/theme-chalk/index.css";
import animated from "animate.css";
// 引入全局样式
import "./assets/css/global.css";
import NProgress from "nprogress"; //引入nprogress
import "nprogress/nprogress.css"; //这个样式必须引入
import { getAccessToken } from "@/api/ys7";

import VideoPlayer from "vue-video-player";

// 引入方式一
import "vue-video-player/src/custom-theme.css";
import "video.js/dist/video-js.css";

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(animated);
Vue.use(drag);
Vue.use(VideoPlayer);
// 简单配置
NProgress.inc(0.2);
NProgress.configure({ easing: "ease", speed: 500, showSpinner: false });

router.beforeEach((to, from, next) => {
  NProgress.start();
  next();
});

router.afterEach(() => {
  NProgress.done();
});

new Vue({
  router,
  render: (h) => h(App),
  created() {
    this.init();
  },
  methods: {
    //初始化
    init() {
      var _this = this;
      var ys7 = localStorage.getItem("ys7");
      if (!ys7 || ys7 == "undefined") {
        _this.getAccessToken();
      } else {
        const expireTime = JSON.parse(ys7).expireTime;
        var timeStamp = new Date().getTime();
        if (timeStamp > expireTime) _this.getAccessToken();
      }
      //this.accessToken = JSON.parse(localStorage.getItem("ys7")).accessToken;
    },
    getAccessToken() {
      getAccessToken({
        appKey: "你的appKey",
        appSecret: "你的appSecret",
      }).then((res) => {
        //console.log(res.data.data);
        localStorage.setItem("ys7", JSON.stringify(res.data.data));
      });
    },
  },
}).$mount("#app");
